<template>
  <div class="app-container">
    <!-- 左侧分类栏 -->
    <aside class="sidebar">
      <div class="logo">
        <h2>页面索引</h2>
        <p>所有页面一目了然</p>
      </div>

      <h3 class="category-header">分类筛选</h3>
      <ul class="category-list">
        <li
            v-for="category in categories"
            :key="category.id"
            :class="['category-item', { active: selectedCategory === category.id }]"
            @click="selectCategory(category.id)"
        >
          <span class="category-icon">{{ category.icon }}</span>
          <span class="category-name">{{ category.name }}</span>
          <span class="category-count">{{ getCategoryCount(category.id) }}</span>
        </li>
      </ul>
    </aside>

    <!-- 主内容区域 -->
    <main class="main-content">
      <div class="header">
        <h1>项目页面索引</h1>
        <p>这里汇集了所有子页面的链接，您可以按分类筛选或搜索查找所需页面。</p>
      </div>

      <div class="search-container">
        <input
            v-model="searchTerm"
            class="search-box"
            placeholder="搜索页面..."
            type="text"
        >
        <div class="search-icon">🔍</div>
      </div>

      <div class="grid">
        <div
            v-for="page in filteredPages"
            :key="page.title"
            class="card"
        >
          <div class="card-category">{{ getCategoryName(page.category) }}</div>
          <div class="card-content">
            <h3 class="card-title">{{ page.title }}</h3>
            <p class="card-description">{{ page.description }}</p>
            <a :href="page.url" class="card-link">访问页面</a>
          </div>
        </div>

        <div v-if="filteredPages.length === 0" class="no-results">
          没有找到匹配的页面
        </div>
      </div>
    </main>
  </div>
</template>

<script setup>
import {ref, computed, onMounted} from 'vue'

// 响应式数据
const searchTerm = ref('')
const selectedCategory = ref('all')

// 示例页面数据
const pages = ref([
  {
    title: "用户登录",
    description: "用户登录和身份验证页面，包含用户名密码输入和社交登录选项。",
    url: "login.html",
    category: "auth"
  },
  {
    title: "产品展示",
    description: "展示所有产品的页面，包含产品图片、描述和价格信息。",
    url: "products.html",
    category: "ecommerce"
  },
  {
    title: "关于我们",
    description: "公司介绍、团队展示和历史沿革等信息页面。",
    url: "about.html",
    category: "company"
  },
  {
    title: "联系方式",
    description: "提供公司地址、电话、邮箱和在线联系表单的联系页面。",
    url: "contact.html",
    category: "company"
  },
  {
    title: "用户仪表盘",
    description: "用户个人中心，包含统计数据、快捷操作和个人设置。",
    url: "dashboard.html",
    category: "app"
  },
  {
    title: "博客首页",
    description: "最新文章列表、热门推荐和博客分类导航。",
    url: "blog.html",
    category: "content"
  },
  {
    title: "购物车",
    description: "用户已选商品列表、价格计算和结算入口。",
    url: "cart.html",
    category: "ecommerce"
  },
  {
    title: "数据统计",
    description: "可视化数据展示，包含图表、图形和数据分析工具。",
    url: "analytics.html",
    category: "app"
  },
  {
    title: "设置页面",
    description: "用户偏好设置、通知管理和隐私选项配置。",
    url: "settings.html",
    category: "app"
  },
  {
    title: "用户注册",
    description: "新用户注册账号页面，包含表单验证和条款同意。",
    url: "register.html",
    category: "auth"
  },
  {
    title: "订单历史",
    description: "用户历史订单查询，包含订单状态和详细信息。",
    url: "orders.html",
    category: "ecommerce"
  },
  {
    title: "帮助中心",
    description: "常见问题解答和用户支持文档页面。",
    url: "help.html",
    category: "content"
  }
])

// 分类数据
const categories = ref([
  {id: 'all', name: '全部页面', icon: '📁'},
  {id: 'auth', name: '认证页面', icon: '🔐'},
  {id: 'ecommerce', name: '电商功能', icon: '🛒'},
  {id: 'company', name: '公司信息', icon: '🏢'},
  {id: 'app', name: '应用功能', icon: '📱'},
  {id: 'content', name: '内容页面', icon: '📝'}
])

// 计算属性 - 过滤页面
const filteredPages = computed(() => {
  const term = searchTerm.value.toLowerCase()
  const category = selectedCategory.value

  return pages.value.filter(page => {
    const matchesSearch = term === '' ||
        page.title.toLowerCase().includes(term) ||
        page.description.toLowerCase().includes(term)

    const matchesCategory = category === 'all' || page.category === category

    return matchesSearch && matchesCategory
  })
})

// 方法 - 选择分类
const selectCategory = (categoryId) => {
  selectedCategory.value = categoryId
}

// 方法 - 获取分类名称
const getCategoryName = (categoryId) => {
  const category = categories.value.find(cat => cat.id === categoryId)
  return category ? category.name : categoryId
}

// 方法 - 获取分类计数
const getCategoryCount = (categoryId) => {
  if (categoryId === 'all') return pages.value.length
  return pages.value.filter(page => page.category === categoryId).length
}
</script>

<style scoped>
/* 基础样式 */
.app-container {
  display: flex;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  color: #333;
  line-height: 1.6;
}

/* 侧边分类栏 */
.sidebar {
  width: 250px;
  background: white;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
  padding: 25px 0;
  height: 100vh;
  position: fixed;
  overflow-y: auto;
  z-index: 100;
}

.logo {
  text-align: center;
  margin-bottom: 30px;
  padding: 0 20px;
}

.logo h2 {
  color: #2c3e50;
  font-size: 1.5rem;
  margin-bottom: 5px;
}

.logo p {
  color: #7f8c8d;
  font-size: 0.9rem;
}

.category-header {
  padding: 0 25px;
  margin: 25px 0 15px;
  font-size: 0.9rem;
  text-transform: uppercase;
  color: #7f8c8d;
  letter-spacing: 1px;
}

.category-list {
  list-style: none;
}

.category-item {
  padding: 12px 25px;
  margin: 5px 0;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  border-left: 4px solid transparent;
}

.category-item:hover {
  background: #f8f9fa;
}

.category-item.active {
  background: #f1f9ff;
  border-left-color: #3498db;
  color: #3498db;
}

.category-icon {
  width: 20px;
  height: 20px;
  margin-right: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.category-count {
  margin-left: auto;
  background: #f1f2f6;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.8rem;
}

.category-item.active .category-count {
  background: #3498db;
  color: white;
}

/* 主内容区域 */
.main-content {
  flex: 1;
  margin-left: 250px;
  padding: 30px;
}

.header {
  margin-bottom: 30px;
}

.header h1 {
  font-size: 2.2rem;
  margin-bottom: 10px;
  color: #2c3e50;
}

.header p {
  color: #7f8c8d;
  max-width: 600px;
}

.search-container {
  max-width: 500px;
  margin-bottom: 30px;
  position: relative;
}

.search-box {
  width: 100%;
  padding: 15px 45px 15px 20px;
  border: none;
  border-radius: 50px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  font-size: 1rem;
  transition: all 0.3s ease;
}

.search-box:focus {
  outline: none;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
  transform: translateY(-2px);
}

.search-icon {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  color: #7f8c8d;
}

/* 页面卡片网格 */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 25px;
}

.card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
  position: relative;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 25px rgba(0, 0, 0, 0.15);
}

.card-category {
  position: absolute;
  top: 15px;
  right: 15px;
  background: rgba(255, 255, 255, 0.9);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  color: #3498db;
  font-weight: 500;
}

.card-content {
  padding: 25px;
}

.card-title {
  font-size: 1.3rem;
  margin-bottom: 10px;
  color: #2c3e50;
}

.card-description {
  color: #7f8c8d;
  margin-bottom: 20px;
  font-size: 0.95rem;
}

.card-link {
  display: inline-block;
  padding: 10px 20px;
  background: linear-gradient(90deg, #3498db, #2ecc71);
  color: white;
  text-decoration: none;
  border-radius: 50px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.card-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
}

.no-results {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px;
  color: #7f8c8d;
}

/* 响应式设计 */
@media (max-width: 992px) {
  .sidebar {
    width: 200px;
  }

  .main-content {
    margin-left: 200px;
  }
}

@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    padding: 15px;
  }

  .main-content {
    margin-left: 0;
    padding: 20px;
  }

  .category-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 10px;
  }

  .category-item {
    flex: 0 0 auto;
    border-left: none;
    border-bottom: 3px solid transparent;
    margin: 0 5px;
    border-radius: 8px;
    white-space: nowrap;
  }

  .category-item.active {
    border-left: none;
    border-bottom-color: #3498db;
  }

  .category-header {
    display: none;
  }
}

/* 滚动条样式 */
.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.sidebar::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}
</style>